<?php
/**
 * Created by PhpStorm
 * User: honglin
 * Date: 2022/8/4
 * Time: 下午5:20
 */

namespace App\Library\Token;



use Hyperf\Redis\Redis;

class SystemAdminCreateTokenLibrary
{
    protected $token_pre = 'Admin:';

    private $adminId;

    private $token;

    public function __construct($adminId)
    {
        $this->adminId = $adminId;
    }

    public static function init($adminId){
        return new static($adminId);
    }

    protected function createToken(){
        return  $this->token = time() . rand(10000, 9999999) . $this->adminId;
    }

    public function create(){
        $this->createToken();
        $this->cacheToken();
        return $this->getToken();
    }

    protected function cacheToken(){
        return App(Redis::class)->set($this->token_pre.$this->token,$this->adminId);
    }

    protected function getToken(){
        return $this->token;
    }
}